package stu.day39_day.day43;

import java.util.Arrays;
import java.util.Scanner;

public class hw3 {


    public static int fun1(int n,int[] arr,int k){
        int sum = Arrays.stream(arr).sum();
        int[][] dp = new int[n+1][sum+1];

        for(int i=0;i<=n;i++){
           dp[i][0] = 1;
        }
        for(int i=1;i<=n;i++){
            for(int j=0;j<=sum;j++){
                if(arr[i-1]>j){
                    dp[i][j] = dp[i-1][j];
                }else {
                    dp[i][j] = dp[i-1][j] + dp[i-1][j-arr[i-1]];
                }
            }
        }
        int num = 0;
        for(int j=1;j<=sum;j++){
            num = num + dp[n][j];
            if(num>=k){
                return j;
            }
        }

        return 0;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int k = Integer.parseInt(str[1]);

        int[] arr = new int[n];
        String[] str2 = sc.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(str2[i]);
        }

        System.out.println(fun1(n, arr, k));

    }
}
